package com.tanhua.sso.server.controller;

import cn.hutool.core.util.StrUtil;
import com.tanhua.result.Result;
import com.tanhua.sso.server.service.TanhuaService;
import com.tanhua.sso.vo.NearbyUserVo;
import com.tanhua.sso.vo.TodayBest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("tanhua")
public class TanhuaController {

    @Autowired
    private TanhuaService tanhuaService;

    //今日佳人
    @GetMapping("todayBest")
    public ResponseEntity todayBest(){
        TodayBest best=tanhuaService.selectOne();
        return ResponseEntity.status(200).body(best);
    }

    //佳人推荐
    @GetMapping("recommendation")
    public ResponseEntity recommendation(){
        List<TodayBest> list=tanhuaService.selectAll();
        return ResponseEntity.ok(new Result(1,10,list));
    }

    /*佳人信息*/
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity personalInfo(@PathVariable Long id){
        TodayBest todayBest=tanhuaService.personalInfo(id);
        return ResponseEntity.ok(todayBest);
    }

    /*查看陌生人问题*/
    @GetMapping("strangerQuestions")
    public ResponseEntity strangerQuestions(Long userId){
        String strangerQuestions=tanhuaService.getStrangerQuestions(userId);
        return ResponseEntity.ok(strangerQuestions);
    }

    /*回复陌生人问题*/
    @PostMapping("/strangerQuestions")
    public ResponseEntity replyQuestions(@RequestBody Map map) {
        //前端传递的userId:是Integer类型的
        String obj = map.get("userId").toString();
        Long userId = Long.valueOf(obj);
        String reply = map.get("reply").toString();
        tanhuaService.sendstrangerQuestions(userId,reply);
        return ResponseEntity.ok(null);
    }

    //探花左滑右滑
    @GetMapping("cards")
    public ResponseEntity cards(){
        List<TodayBest> list=tanhuaService.cards();
        return ResponseEntity.ok(list);
    }

    /*喜欢*/
    @GetMapping("/{id}/love")
    public ResponseEntity love(@PathVariable Long id){
        boolean flag=true;
        tanhuaService.love(id,flag);
        return ResponseEntity.ok(null);
    }

    /**
     * 不喜欢
     */
    @GetMapping("{id}/unlove")
    public ResponseEntity<Void> notLikeUser(@PathVariable Long id) {
        boolean flag=false;
        tanhuaService.love(id,flag);
        return ResponseEntity.ok(null);
    }

    /*查看附近友好*/
    @GetMapping("search")
    public ResponseEntity search(String gender,Double distance){
        List<NearbyUserVo> nearbyUserVoList=tanhuaService.search(gender,distance);
        return ResponseEntity.ok(nearbyUserVoList);
    }

}
